﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BomberManServer.Gaming.Object.Mapping.Model.States;
using BomberManServer.Utils;

namespace BomberManServer.Gaming.Object.Mapping.Model
{
    public abstract class Map
    {
        // to store the block models
        public Graph<Block> blocks { get; protected set; }

        protected Game game;
        protected List<Model.IBuilder> builders;
        public States.DestructibleBlock destructible { get; private set; }

        // construct the model from the given dimensions
        protected Map(Game game,UInt16 width, UInt16 height)
        {
            destructible = new States.DestructibleBlock(game);
            this.builders = new List<Model.IBuilder>();
            blocks = new Graph<Block>(width,height);
            // initialise the model
            foreach (int index in Enumerable.Range(0, blocks.data.Length))
                blocks.data[index] = new Block(Constants.instance.stateRock);
        }

        // make real blocks from the block models
        public void construct(Graph<Mapping.Block> map)
        {
            foreach (IBuilder builder in builders)
            {
                builder.reset();
            }
            int index = 0;
            foreach (Block block in blocks.data)
            {
                map.data[index] = block.build(map.data[index]);
                index++;
            }
        }
    }
}
